package com.bytezero.team.view;


import com.bytezero.team.domain.Employee;
import com.bytezero.team.domain.Programmer;
import com.bytezero.team.service.NameListService;
import com.bytezero.team.service.TeamException;
import com.bytezero.team.service.TeamService;

/**
 * 
 * @Description     Java  开发人员调度软件项目 (java基础编程总结项目)
 *                +javaBean+测试代码+数组知识+数据结构+继承+多态+封装+自定义异常，异常处理
 *                +构造器知识+重载+重写+接口+实现接口+关键字使用（static +equalsIgnoreCase+fianl+instanceof判断类型）
 *                +向下转型与向上转型
 * @author Bytezero·zhenglei!        Email:420498246@qq.com
 * @version
 * @date 下午12:00:33
 * @     
 *
 */
public class TeamView {

	
	private NameListService listSvc = new NameListService();
	
	private TeamService teamSvc = new TeamService();
	
	public void enterMainMenu() {
		
		
		boolean loopFlag = true;
		char menu =0;
		while(loopFlag) {
			
			if(menu != '1') {
				listAllEmployee();
			}
		
			
			System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4): " );
			menu = TSUtility.readMenuSelection();
			switch(menu) {
			case '1':
				getTeam();
				break;
				
			case '2':
				
				addMember();
				break;
				
			case '3':
				
				deleteMember();
				break;
				
			case '4':
				//System.out.println("退出");
				System.out.print("确认是否要退出(Y/N): ");
				char isExit = TSUtility.readConfirmSelection();
				if(isExit =='Y') {
					loopFlag = false;
					System.out.println("已成功退出！");
				}
				break;
			}
			
		}
		
	}
	/***
	 *  显示所有员工的信息
	 */
	private void listAllEmployee() {
//		System.out.println("显示所有员工的信息");
		
		System.out.println("---------------------------------开发团队调度软件--------------------------------------");
		System.out.println("                                                 ----author:  (Bytezero·zhenglei!)\n");
		
		Employee[] employees = listSvc.getAllEmployees();
		if(employees == null && employees.length ==0) {
			System.out.println("公司中没有任何员工信息！");
		}else {
			System.out.println("ID\t姓名\t年龄\t工资\t职位\t状态\t奖金\t股票\t领用设备");
			
			for(int i =0;i<employees.length;i++) {
				System.out.println(employees[i]);
			}
			
		}
		System.out.println("----------------------------------------------------------------------------------------");
		
	}
	private void getTeam() {
//		System.out.println("查看开发团队情况");
		
		System.out.println("--------------------团队成员列表--------------------\n");
		
		Programmer[] team = teamSvc.getTeam();
		if(team == null || team.length ==0) {
			System.out.println("开发团队目前没有成员！");
			
		}else {
			System.out.println("TID/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票\n");
			for(int i =0;i<team.length;i++) {
				System.out.println(team[i].getDetailsForTeam());
			}
		
		}
		
		System.out.println("---------------------------------------------------");
		
		
		
	}
	private void addMember() {
//		System.out.println("添加团队成员");
		
		System.out.println("----------------------添加成员----------------------");
		System.out.print("请输入要添加成员的ID：");
		int id = TSUtility.readInt();
		
		try {
			Employee emp = listSvc.getEmployee(id);
			teamSvc.addMenmber(emp);
			System.out.println("添加成功");
			
			
		} catch (TeamException e) {
			System.out.println("添加失败，原因："+ e.getMessage());
		}
	 
		//按回车键继续
		TSUtility.readReturn();
	
	
	}
	private void deleteMember() {
//		System.out.println("删除团队成员");
		System.out.println("----------------------删除员工----------------------");
		System.out.println("请输入要删除员工的TID: ");
		int memberId = TSUtility.readInt();
		
		
		System.out.print("确认是否删除(Y/N): ");
		char isDelete = TSUtility.readConfirmSelection();
		if(isDelete=='N') {
			return;
		}
		try {
			teamSvc.removeMember(memberId);
			System.out.println("删除成功");
		} catch (TeamException e) {
			System.out.println("删除失败，原因："+e.getMessage());
		}
		
		//按回车键继续
		TSUtility.readReturn();
		
	}
	
	
	
	public static void main(String[] args) {
		TeamView view = new TeamView();
		view.enterMainMenu();
	}
}

